import { defineStore } from 'pinia'
import {
  getArticalClass,
  addArtical,
  updateArtical,
  deleteArtical
} from '../../api/artical'
import { ref } from 'vue'
export const articalStore = defineStore(
  'articalStore',
  () => {
    const articalList = ref()
    const getArticalList = async () => {
      const res = await getArticalClass()
      articalList.value = res.data.data
    }
    const increArtical = async (data) => {
      await addArtical(data)
      getArticalList()
    }
    const update = async (data) => {
      updateArtical(data)
    }
    const delArtical = async (id) => {
      await deleteArtical(id)
      getArticalList()
    }
    return { getArticalList, articalList, increArtical, update, delArtical }
  },
  {
    persist: true
  }
)
